package com.whitedust.top50;

import java.util.Stack;

/**
 * @author A
 * @since 2025/11/7 12:55
 */

public class Top41 {
    public static class MyQueue {
        private final Stack<Integer> rev = new Stack<>();
        private final Stack<Integer> que = new Stack<>();

        public MyQueue() {

        }

        public void push(int x) {
            rev.push(x);
        }

        public int pop() {
            if (que.isEmpty()) {
                int size = rev.size();
                for (int i = 0; i < size; i++) {
                    que.push(rev.pop());
                }
            }
            return que.pop();
        }

        public int peek() {
            if (que.isEmpty()) {
                int size = rev.size();
                for (int i = 0; i < size; i++) {
                    que.push(rev.pop());
                }
            }
            return que.peek();
        }

        public boolean empty() {
            return rev.isEmpty() && que.isEmpty();
        }
    }

    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1);
        myQueue.push(2);
        System.out.println(myQueue.peek());
    }
}
